<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>resolve</title>
</head>
<body>
  <script>
    'use strict'
    onload = function () {
      /* 
        resolve 介绍
          1.resolve 用于快速将一个值包装成一个成功的 Promise 实例
          2.当传入的值为一个 Promise 实例时，resolve 返回的 Promise 实例与其保持一致
      */

      const A = new Promise((resolve, reject) => {
        try {
          // 模拟异常
          // throw new Error('数据A请求异常')
          // 模拟请求
          setTimeout(() => {
            console.log('数据A请求成功')
            resolve('数据A')
          }, 2000)
        } catch (error) {
          reject(error)
        }
      })

      const result = Promise.resolve(A)
      // console.log(result)
      result.then((value) => {
        console.log(value)
      }).catch((reason) => {
        console.log(reason)
      })
    }
  </script>
</body>
</html>